#include "HillHunter.h"
#include "State.h"

void HillHunter::operator()(const Target::AntVector::value_type& hill)
{
    WeightTask nearestAnt;
    if (findTarget(hill, nearestAnt))
    {
//        OUT_PRINT "HILL FOUND: " << hill << " nearest ant " << nearestAnt.first << std::endl;
        assign(nearestAnt.first, std::make_pair(hill,nearestAnt.second));
    }
}

template <typename T>
struct CanMoveFrom
{
    CanMoveFrom(T* state) : state(state) {}

    bool operator () (const Hill& hill, const Ant& ant) const
    {
        return state->canMove(ant, hill);
    }

    T* state;
};


bool HillHunter::findTarget(const Target::AntVector::value_type& hill, WeightTask& result)
{
    return FindNearestTarget(hill, state->myAnts, state->GetMapResolution(), result, CanMoveFrom<State>(state));
}

